import requests
import re
newsurl='http://news.sina.com.cn/c/2018-05-28/doc-ihcffhsu5347631.shtml'
res=requests.get(newsurl)
res.encoding='utf-8'
sample=res.text
from bs4 import BeautifulSoup
soup=BeautifulSoup(sample,'html.parser')


newsUrl='http://news.sina.com.cn/c/2018-05-28/doc-ihcffhsu5347631.shtml'
newsid=newsUrl.split('/')[-1].rstrip('.shtml').lstrip('doc-i')
print(newsid)

#使用re正则表达式
m=re.search('doc-i(.*).shtml',newsUrl)
print(m.group(1))
